"""
调用Activity相关函数例子的UI层。
"""
import asyncio
import typing

from elio import core


class ActivityFuncLayer(core.AutoRecycleLayer[core.Activity]):
    cbEnableTouchExploration: core.WidgetCheckBox

    async def on_create(self, *args: typing.Any, **kwargs: typing.Dict):
        await super().on_create(*args, *kwargs)

    async def on_hide(self):
        await super().on_hide()
        await self.cbEnableTouchExploration.destroy()

    async def on_show(self):
        await super().on_show()
        activity = self.parent
        # 获取设备信息
        print('Client-IP', activity.client_ip)
        print('Client-ID', activity.client_id)
        print('User-Agemt', activity.user_agent)
        print('Platform', activity.platform)
        print('ScreenSize', await activity.get_screen_size())
        # 设置和获取标题测试
        await activity.set_title('请登录')
        print('Title', await activity.get_title())
        # 发送无障碍通知的测试
        await asyncio.sleep(1)
        await activity.accessibility_notice('赶快登录吧！')
        # 启用触摸浏览
        self.cbEnableTouchExploration = await core.WidgetCheckBox.create(activity, 200, 50, 0, 0, '启用触摸浏览')

        async def cb1():
            """
            复选框点击事件。
            """
            checked = await self.cbEnableTouchExploration.is_checked()
            # 开启或关闭触摸浏览测试
            await activity.set_touch_exploration(checked)

        await self.cbEnableTouchExploration.set_on_click_listener(cb1)
        await activity.set_clipboard_text('sscn.byethost3.com')
        print(await activity.get_clipboard_text())

    async def on_destroy(self, *args: typing.Any, **kwargs: typing.Dict):
        await super().on_destroy(*args, **kwargs)

    async def on_pause(self):
        await super().on_pause()

    async def on_resume(self):
        await super().on_resume()
